class Solution {
    public int findShortestSubArray(int[] nums) {
    // 用哈希表纪录数组中的元素出现的连续起点，终点和次数
    // 找出哈希表中最大的度和最小的连续长度，回传最小的连续长度
        
        int n = nums.length;
        Map<Integer, int[]> map = new HashMap<Integer, int[]>();
        int[] mp_arr = {};
        for (int i = 0; i< n; i++) {
            if(map.containsKey(nums[i])){
                System.out.println("Not the first");
                mp_arr = map.get(nums[i]);
                mp_arr[0]++;
                mp_arr[2] = i;
                map.put(nums[i], mp_arr);
            } else {
                System.out.println("first");
                
                map.put(nums[i],new int[]{1,i,i});
            }
            
        }
        
        int maxDegree = 0; //纪录最大的度
        int minLen = n; // 记录最短的字串长度 = 最后的位置 - 最初的位置
        
        for (Map.Entry<Integer, int[]> entry: map.entrySet()) {
            int[] result_arr = entry.getValue();
            System.out.println(result_arr[0]+":"+result_arr[1]+":"+result_arr[2]);
            if (result_arr[0] > maxDegree) {
                maxDegree = result_arr[0];
                minLen = result_arr[2] - result_arr[1] + 1;
            }
            if (maxDegree == result_arr[0]) {
                int len = result_arr[2] - result_arr[1] + 1;
                if (len < minLen ) minLen = len;
                
            }
            System.out.println(entry.getKey()+":"+"cnt:"+result_arr[0]+",pos1:"+result_arr[1]+",pos2:"+result_arr[2]);
            System.out.println("Max Degree="+maxDegree+",Min Length="+minLen);
        }
        
        
        return minLen;
    }
}